﻿@using EcBlog.Properties
@using Telerik.Web.Mvc.UI
@{  
    ViewBag.Title = "Manage Tags";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}
@section head {
    @Html.Partial("_Head")
    <script type="text/javascript">
        function onError(e) {
            e.preventDefault();
            alert(e.XMLHttpRequest.getResponseHeader("message"));
        }

        function onLoadTagGrid() {
            replaceNewButtonText($(this), '@ModelLocalization.NewTag');
        }
        function onDataBoundTagGrid() {
            replaceDeleteConfirmation(this, '@ModelLocalization.DeleteConfirmation', '@ModelLocalization.Tag');
        }
        function onEditTagGrid(e) {
            replaceEditPopupTitle(e, '@ModelLocalization.NewTag', '@ModelLocalization.EditTag');
            hideEditPopupField(e, 'TagId');
        } 
       
    </script>
}
 @(Html.Telerik().Grid<EcBlog.Models.Tag>()
    .Name("TagGrid") 
    .Columns(columns =>
    {
        columns.Command(commands =>
        {
            commands.Edit()
                .ButtonType(GridButtonType.Image);
            commands.Delete()
                .ButtonType(GridButtonType.Image);
        }).Width(80);
        columns.Bound(c => c.TagName);
        columns.Bound(c => c.TagSlug);
    })
    .DataBinding(dataBinding => 
        dataBinding.Ajax()
            .Insert("Insert", "Tag", new { area = "Admin"})
            .Select("List", "Tag", new { area = "Admin" })
            .Delete("Delete", "Tag", new { area = "Admin" })
            .Update("Edit", "Tag", new { area = "Admin" }))
    .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText))
    .DataKeys(keys => keys.Add(c => c.TagId).RouteKey("TagId"))
    .Pageable(p => p.PageSize(100))
    .Scrollable()
    .KeyboardNavigation()
    .Filterable()
    .Groupable()
    .Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn))
    .Reorderable(c => c.Columns(true))
    .Resizable(c => c.Columns(true))
    .Editable(c => c.Mode(GridEditMode.PopUp))
    .EnableCustomBinding(true)
    .ColumnContextMenu()
    .ClientEvents(events =>
    events
        .OnError("onError")
        .OnLoad("onLoadTagGrid")
        .OnDataBound("onDataBoundTagGrid")
        .OnEdit("onEditTagGrid"))
)

